package leetcode.median;

public class $376_WiggleMaxLength {
    public int wiggleMaxLength(int[] nums) {
        int len = nums.length;
        if (len <= 1)
            return len;

        int res = 1;
        int preDiff = 0;
        int curDiff = 0;
        for (int i  = 0;i < len - 1;i++) {
            curDiff = nums[i + 1] - nums[i];
            if ((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) {
                res++;
                preDiff = curDiff;
            }
        }
        return res;
    }
}
